package com.site.wisdom_construction.controller.scheduleModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.scheduleModule.AerialProgressService;
import com.site.wisdom_construction.util.verification.NoToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/12
 * @Description
 */
@Api(tags = "航拍进度接口")
@RestController
@RequestMapping("AerialProgress")
@CrossOrigin
public class AerialProgressController {
    @Autowired
    private AerialProgressService aerialProgressService;

    @ApiOperation(value = "增加航拍进度", notes = "测试数据:")
    @PostMapping("/insertAerialProgress")
    public JsonResult insertAerialProgress(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = aerialProgressService.insertAerialProgress(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入航拍进度!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入航拍进度失败!");
        }
        return jsonResult;
    }


    @ApiOperation(value = "删除航拍进度信息", notes = "测试数据:")
    @PostMapping("/deleteAerialProgress")
    public JsonResult deleteAerialProgress(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = aerialProgressService.deleteAerialProgress(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除航拍进度!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除航拍进度失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改航拍进度", notes = "测试数据:")
    @PostMapping("/updateAerialProgress")
    public JsonResult updateAerialProgress(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = aerialProgressService.updateAerialProgress(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改航拍进度!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改航拍进度失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询航拍进度", notes = "测试数据:")
    @PostMapping("/findAerialProgressByPage")
    public Page findAerialProgressByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(aerialProgressService.Total(map));
        page.setItems(aerialProgressService.findAerialProgressByPage(map));
        return page;
    }

    @ApiOperation(value = "查询全部航拍进度", notes = "测试数据:")
    @RequestMapping("/selectAerialProgress")
    @NoToken
    public OneDataResult selectAerialProgress(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(aerialProgressService.selectAerialProgress(map));
        return oneDataResult;
    }
}
